package com.gw.vip.server.controller;

import com.gw.vip.common.log.PrintlnLog;
import com.gw.vip.common.vo.Result;
import com.gw.vip.server.dto.SetIssuInfoDto;
import com.gw.vip.server.dto.SetMailInfoDto;
import com.gw.vip.server.service.SettingService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author GW
 * @description 系统配置
 * @since 2022-09-23
 */
@RestController
@RequestMapping("setting")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class SettingController {

    private final SettingService settingService;

    @PrintlnLog(description = "设置发行机构信息")
    @PostMapping("setIssuInfo")
    public Result setIssuInfo(@RequestBody @Valid SetIssuInfoDto dto){
        settingService.setIssuInfo(dto);
        return Result.success();
    }

    @PrintlnLog(description = "设置邮箱信息")
    @PostMapping("setMailInfo")
    public Result setMailInfo(@RequestBody @Valid SetMailInfoDto dto){
        settingService.setMailInfo(dto.getUserName(), dto.getPassword());
        return Result.success();
    }
}
